<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>Zookeeper安装 | </title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="baidu-site-verification" content="T7hOozd75A">
  <meta name="description" content="1. 安装程序zookeeper-3.4.11 2 .环境要求 1.ZK的系统支持情况   Client is the Java client library, used by applications to connect to a ZooKeeper ensemble.  Java客户端   Server is the Java server that runs on the ZooKeep">
<meta name="keywords" content="zookeeper,安装">
<meta property="og:type" content="article">
<meta property="og:title" content="Zookeeper安装">
<meta property="og:url" content="http://lowezheng.gitee.io/2018/12/01/zookeeper/index.html">
<meta property="og:site_name">
<meta property="og:description" content="1. 安装程序zookeeper-3.4.11 2 .环境要求 1.ZK的系统支持情况   Client is the Java client library, used by applications to connect to a ZooKeeper ensemble.  Java客户端   Server is the Java server that runs on the ZooKeep">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-12-04T00:57:27.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Zookeeper安装">
<meta name="twitter:description" content="1. 安装程序zookeeper-3.4.11 2 .环境要求 1.ZK的系统支持情况   Client is the Java client library, used by applications to connect to a ZooKeeper ensemble.  Java客户端   Server is the Java server that runs on the ZooKeep">
  
    <link rel="alternate" href="/atom.xml" title="" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo"></a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">主页</a>
        
          <a class="main-nav-link" href="/archives">文档库</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form target="_blank" action="http://zhannei.baidu.com/cse/site" class="search-form">
            <input type="text" name="q" class="search-form-input" size="30">
            <input type="hidden" name="cc" value="lowezheng.gitee.io">
        </form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-zookeeper" class="article article-type-post" itemscope="" itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/12/01/zookeeper/" class="article-date">
  <time datetime="2018-12-01T07:58:30.000Z" itemprop="datePublished">2018-12-01</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Zookeeper安装
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<h2 id="1-安装程序"><a href="#1-安装程序" class="headerlink" title="1. 安装程序"></a>1. 安装程序</h2><p><a href="https://archive.apache.org/dist/zookeeper/zookeeper-3.4.11/" target="_blank" rel="noopener">zookeeper-3.4.11</a></p>
<h2 id="2-环境要求"><a href="#2-环境要求" class="headerlink" title="2 .环境要求"></a>2 .环境要求</h2><p><strong> 1.ZK的系统支持情况 </strong></p>
<ul>
<li><p>Client is the Java client library, used by applications to connect to a ZooKeeper ensemble.</p>
<ul>
<li>Java客户端</li>
</ul>
</li>
<li><p>Server is the Java server that runs on the ZooKeeper ensemble nodes.</p>
<ul>
<li>Java服务端</li>
</ul>
</li>
<li><p>Native Client is a client implemented in C, similar to the Java client, used by applications to connect to a ZooKeeper ensemble.</p>
<ul>
<li>C客户端</li>
</ul>
</li>
<li><p>Contrib refers to multiple optional add-on components.</p>
<ul>
<li>搞不懂</li>
</ul>
</li>
</ul>
<table>
<thead>
<tr>
<th>操作系统</th>
<th>Client</th>
<th>Server</th>
<th>NativeClient</th>
<th>Contrib</th>
</tr>
</thead>
<tbody>
<tr>
<td>Linux</td>
<td>支持</td>
<td>支持</td>
<td>支持</td>
<td>支持</td>
</tr>
<tr>
<td>Solaris</td>
<td>支持</td>
<td>支持</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>FreeBSD</td>
<td>支持</td>
<td>支持</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Windows</td>
<td>支持</td>
<td>支持</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Mac OS X</td>
<td>开发版支持</td>
<td>开发版支持</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
<p><strong> 2.JVM要求 </strong></p>
<ul>
<li>java6+</li>
</ul>
<h2 id="3-安装"><a href="#3-安装" class="headerlink" title="3. 安装"></a>3. 安装</h2><p>拷贝zoo_sample.cfg为zoo.cfg</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp zoo_sample.cfg zoo.cfg</span><br></pre></td></tr></table></figure>
<h3 id="1-单机版配置-zoo-cfg"><a href="#1-单机版配置-zoo-cfg" class="headerlink" title="1.单机版配置[zoo.cfg]"></a>1.单机版配置[zoo.cfg]</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 心跳时间</span></span><br><span class="line">tickTime=2000</span><br><span class="line"><span class="comment"># 数据存储目录</span></span><br><span class="line">dataDir=/var/lib/zookeeper</span><br><span class="line"><span class="comment"># 服务端口</span></span><br><span class="line">clientPort=2181</span><br></pre></td></tr></table></figure>
<h3 id="2-集群版配置-zoo-cfg"><a href="#2-集群版配置-zoo-cfg" class="headerlink" title="2.集群版配置[zoo.cfg]"></a>2.集群版配置[zoo.cfg]</h3><p><code>注意：集群部署节点个数必须是奇数，其次只有过半数节点正常工作，集群才能正常提供服务</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">tickTime=2000</span><br><span class="line">dataDir=/var/lib/zookeeper</span><br><span class="line">clientPort=2181</span><br><span class="line"># 当follower最初与leader建立连接时，它们之间会传输相当多的数据，尤其是follower的数据落后leader很多,follower与leader之间建立连接后进行同步的最长时间</span><br><span class="line">initLimit=5</span><br><span class="line"># 配置follower和leader之间发送消息，请求和应答的最大时间长度</span><br><span class="line">syncLimit=2</span><br><span class="line"># 集群节点的IP</span><br><span class="line"># server.&lt;myid&gt;=&lt;服务器地址&gt;:&lt;LF通讯端口&gt;:&lt;选举端口&gt;</span><br><span class="line">server.1=zoo1:2888:3888</span><br><span class="line">server.2=zoo2:2888:3888</span><br><span class="line">server.3=zoo3:2888:3888</span><br></pre></td></tr></table></figure>
<p>设置节点的id,与集群配置保持一致。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">echo &apos;1&apos; &gt; data/myid</span><br></pre></td></tr></table></figure></p>
<h3 id="3-启动服务"><a href="#3-启动服务" class="headerlink" title="3.启动服务"></a>3.启动服务</h3><p>进入bin目录<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">./zkServer.sh start</span><br><span class="line"></span><br><span class="line"><span class="comment">#重启服务</span></span><br><span class="line"><span class="comment">#./zkServer.sh restart</span></span><br><span class="line"><span class="comment">#关闭服务</span></span><br><span class="line"><span class="comment">#./zkServer.sh stop</span></span><br></pre></td></tr></table></figure></p>
<h2 id="4-网络要求"><a href="#4-网络要求" class="headerlink" title="4.网络要求"></a>4.网络要求</h2><p>如果有开启防火墙，需要开放端口</p>
<table>
<thead>
<tr>
<th>端口号</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>2181</td>
<td>zk客户端接入端口</td>
</tr>
<tr>
<td>2888</td>
<td>Leader和Follwer的数据同步端口</td>
</tr>
<tr>
<td>3888</td>
<td>Zk节点的选举通信端口</td>
</tr>
</tbody>
</table>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://lowezheng.gitee.io/2018/12/01/zookeeper/" data-id="cjp9hvybd00045yf0qu9nxnp6" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/zookeeper/">zookeeper</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/安装/">安装</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2018/12/04/mac-command/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Mac指令集合
        
      </div>
    </a>
  
  
    <a href="/2018/11/29/operesty/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">OpenrestyTCP反向代理-EQMX高可用</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/EMQX/">EMQX</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MQTT/">MQTT</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ca/">ca</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/openresty/">openresty</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/openssl/">openssl</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/内存溢出/">内存溢出</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/反向代理/">反向代理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/安装/">安装</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/自建证书/">自建证书</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/EMQX/" style="font-size: 10px;">EMQX</a> <a href="/tags/MQTT/" style="font-size: 10px;">MQTT</a> <a href="/tags/ca/" style="font-size: 10px;">ca</a> <a href="/tags/openresty/" style="font-size: 10px;">openresty</a> <a href="/tags/openssl/" style="font-size: 10px;">openssl</a> <a href="/tags/tomcat/" style="font-size: 10px;">tomcat</a> <a href="/tags/zookeeper/" style="font-size: 10px;">zookeeper</a> <a href="/tags/内存溢出/" style="font-size: 10px;">内存溢出</a> <a href="/tags/反向代理/" style="font-size: 10px;">反向代理</a> <a href="/tags/安装/" style="font-size: 10px;">安装</a> <a href="/tags/自建证书/" style="font-size: 10px;">自建证书</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">十二月 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">十一月 2018</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2018/12/04/mac-command/">Mac指令集合</a>
          </li>
        
          <li>
            <a href="/2018/12/01/zookeeper/">Zookeeper安装</a>
          </li>
        
          <li>
            <a href="/2018/11/29/operesty/">OpenrestyTCP反向代理-EQMX高可用</a>
          </li>
        
          <li>
            <a href="/2018/11/29/openssl/">Openssl自建CA</a>
          </li>
        
          <li>
            <a href="/2018/11/29/tomcat/">Tomcat内存溢出跟踪</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2018 lowe zheng<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">主页</a>
  
    <a href="/archives" class="mobile-nav-link">文档库</a>
  
</nav>
    

<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>